package com.czk.model.state.practice;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/9 14:41
 */
public class OrderProcessing implements OrderState {
    private static OrderProcessing orderProcessing = new OrderProcessing();

    @Override
    public void updateState(OrderContext orderContext) {
        boolean b = ThreadLocalRandom.current().nextBoolean();
        if (b) {
            System.out.println("用户支付成功");
            // 修改状态
            orderContext.setCurrentState(OrderPaySuccess.instance());
        } else {
            System.out.println("用户支付失败");
            // 修改状态
            orderContext.setCurrentState(OrderPayFail.instance());
        }
    }

    private OrderProcessing() {
    }

    public static OrderProcessing instance() {
        return orderProcessing;
    }
}
